-
Notifications
You must be signed in to change notification settings - Fork 93
DRAFT - Fix Various Home / End key binding issues #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
many terminals will only use terminfo string in application mode. smkx commands will transition the terminal to the correct mode.
Cleanup some line spacing, add comments in case people want to know what the code does add at_exit block so that we return the console back to rx mode upon exist
…vi key command list
|
Added in delete key functionality for terminfo and added in to the vi list |
|
Removed key_delete from line_editor as it was not necessary. |
| config.add_default_key_binding_by_keymap(:emacs, key, func) | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 10 lines of code already exist below, so now it is in two places. Did you mean to remove it from below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes, I'll clean that up.
|
|
||
| def self.set_default_key_bindings_terminfo(config) | ||
|
|
||
| # put terminal in tx mode so that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Put terminal in keypad transmit mode" would be a little more accurate.
| # capname is undefined | ||
| end | ||
|
|
||
| # return terminal to rx mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs to be fixed too. It's not about "transmit" vs "receive". Leaving keypad transmit mode doesn't mean the terminal goes into "receive" mode.
I think either of these would work fine:
- "Leave keypad transmit mode"
- "Return terminal to normal mode".
For more context, consider xterm: with xterm smkx turns into \E[?1h and \E=, which sets the cursor keys and keypad to application mode, whereas rmkx turns into \E[?1l and \E>, which sets the cursor keys and keypad to normal mode.
|
@kcculhwch I noticed that your PR here has some overlap with my PR, which makes me wonder if we should combine them in some way... For example, if you want to pull my changes into yours (mine is only 4 lines), that might be a good idea and then perhaps I'll delete mine (or if nothing else, at least there won't be a conflict when they both get merged). Speaking of getting merged, my PR is only 4 lines long yet sadly nothing happened on it for 6 months. Then 11 days ago I was asked if I could add some tests, but I haven't quite figured out how to do that yet. |
|
@sshock I'll go ahead and pull your changes into mine when I get a moment. |
| 'cud' => :ed_next_history, | ||
| 'cuf' => :ed_next_char, | ||
| 'cub' => :ed_prev_char, | ||
| 'kdch1' => :key_delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kcculhwch, I have another suggestion that makes sense to include in your PR:
The four lines above this for 'cuu', 'cud', 'cuf', and 'cub' don't belong and should be removed (along with the special handling for them on lines 100-101). With your smkx fix in place, I don't think they'll be needed anymore.
I think what happened is @aycabta discovered that the cursor keys weren't working with some terminal emulators, including xterm, and he discovered that by mapping these it fixed it.
But that wasn't the right fix; the right fix is your PR, because as you and I both discovered independently, until the terminal has been set to 'smkx' mode, the home and end keys may send different escape sequences that don't align with the output of terminfo. Well, the same is true for the cursor keys.
In other words, this list already includes 'kcuu1', 'kcud1', 'kcuf1', and 'kcub1', which are the correct things to map for the arrow keys. They just weren't working (for some terminals) because reline wasn't putting the terminal in 'smkx' mode. Now with your PR they will work.
The escape sequences for 'cuu', 'cud', 'cuf', and 'cub' are not something the terminal sends when arrow keys are pressed! They are what you send to the terminal to make the cursor move.
It just so happens that in some terminals (well xterm at least), the escape sequences for 'cuu', 'cud', 'cuf', and 'cub' with the "%p1%d" removed from the middle happen to result in the escape sequences for the arrow keys in normal mode, but we don't need to rely on this happenstance anymore.
| begin | ||
| @@output.write Reline::Terminfo.tigetstr('rmkx') | ||
| rescue Reline::Terminfo::TerminfoError | ||
| # capname is undefined | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you can avoid the extra begin/end for the rescue to work inside the block since #12906.
@kcculhwch My PR got merged last month, so the key binding for delete is now there in master. Do you want to update your branch against the latest and continue with this PR (including the cleanups we talked about)? Home and End are still very much broken, at least with xterm, until we get this PR in. As we both know, an application must enter keypad-transmit mode to ensure key codes align with terminfo. |
|
Yeah. I’ve been a bit too busy lately to revisit. If I get a chance this
week I’ll go ahead and do that.
…On Sat, Feb 4, 2023 at 12:03 PM Phillip Hellewell ***@***.***> wrote:
@sshock <https://github.com/sshock> I'll go ahead and pull your changes
into mine when I get a moment.
@kcculhwch <https://github.com/kcculhwch> My PR
<#434> got merged last month, so the
key binding for delete is now there in master.
Do you want to update your branch against the latest and continue with
this PR (including the cleanups we talked about)?
Home and End are still very much broken, at least with xterm, until we get
this PR in. As we both know, an application must enter keypad-transmit mode
to ensure key codes align with terminfo.
—
Reply to this email directly, view it on GitHub
<#462 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVCIGHYZLAR7AU6ULCKLMLWV2DW7ANCNFSM57TNXQ7Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
| end | ||
|
|
||
| # return terminal to rx mode | ||
| at_exit do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should send the "smkx" and "rmkx" in prep and deprep rather than doing it here in set_default_key_bindings_terminfo and having to rely on an at_exit, which can be problematic.
|
@kcculhwch I created a new PR that is similar to this one, but incorporates all the feedback here. The main difference is it sends "smkx" and "rmkx" in Let me know what you think and if you want to close out this PR now you can. |
|
@kcculhwch can you close this out? After talking with @tompng in #521, it is more clear to me that entering application mode has additional nuances we would need to handle. We are going to move forward with a different solution, probably #567. |
|
@sshock 👋 While I appreciate your passion and effort on solving the issue, can you please don't ask other contributors to close their PRs before we actually merge a solution? |
|
I don't mind either way, my work has taken me out of this convo for a
while. Happy to close this out if it's no longer helping move the
conversation forward, but if keeping it open is helping find a better
solution, I don't mind keeping it open either.
…On Tue, Jul 11, 2023 at 11:00 AM Stan Lo ***@***.***> wrote:
@sshock <https://github.com/sshock> 👋 While I appreciate your passion
and effort on solving the issue, can you please don't ask other
contributors to close their PRs before we actually merge a solution?
—
Reply to this email directly, view it on GitHub
<#462 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVCIGF6YXLANVD2MENRQKDXPVTAJANCNFSM57TNXQ7Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@sshock No worries. Thanks for pushing the issue forward 👍 |
|
This is fixed by #569 |
After playing around with various keybinding issues affecting MacOS, iTerm2, and other ncurses loading terminal emulators, I stumbled upon references to switching the terminal mode so that key bindings align with the output of terminfo (infocmp) for kend and khome. Basically, until the terminal emulator has been set to 'smkx' ("keypad-transmit" mode) home/end keys send normal mode bindings which use a different style escape sequences. This code slots in at the setup phase before we use the ncurses based libraries to gather the keybindings.
If you want to test the intended functionality here prior to pulling try running the following
tput smkx && irbif you want to see what the raw chars look like in various mode
tput smkx && readwill let you see the raw escape code of keypad-transmit modeSome terminals and shells will reset after program exit, but some do not, so to return to receive mode:
tput rmkxNote this is my first PR in this project and I didn't see any submission guidelines... so please let me know what changes would be required.
Note 2 ... MacOS's Terminal.app has a variation of home/end key bindings and prefers shift+home and shift+end but these map to kend and khome rather than kEND and kHOM